feat(generator): add fallback compatibility imports for google-api-core helpers and update goldens - #17999
feat(generator): add fallback compatibility imports for google-api-core helpers and update goldens#17999hebaalazzeh wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the templates to conditionally import several helper functions (get_default_mtls_endpoint, get_api_endpoint, get_universe_domain, and transcode_request) from google.api_core if available, falling back to local implementations on ImportError. It also updates the client template to explicitly pass default_universe="googleapis.com" to get_universe_domain. The feedback correctly points out that the fallback implementation of get_universe_domain in _compat.py.j2 is missing the default value for default_universe, which breaks compatibility with the original signature and the google.api_core version.
| def get_universe_domain( | ||
| *potential_universes: Optional[str], | ||
| default_universe: str, | ||
| ) -> str: |
There was a problem hiding this comment.
The fallback implementation of get_universe_domain is missing the default value for default_universe (default_universe: str = DEFAULT_UNIVERSE). This breaks compatibility with the original signature and with google.api_core.universe.get_universe_domain, which makes default_universe optional. Please restore the default value to ensure it remains a drop-in replacement.
def get_universe_domain(
*potential_universes: Optional[str],
default_universe: str = DEFAULT_UNIVERSE,
) -> str:
Description
Updates
_compat.py.j2to import helper functions (get_default_mtls_endpoint,get_api_endpoint,get_universe_domain, andtranscode_request) fromgoogle-api-core, with fallbacks to local implementations for older versions.Summary of Changes
_compat.py.j2: Addedtry...except ImportErrorfallback imports forgoogle-api-corehelper functions.Note on
setup_request_idsetup_request_idis intentionally kept as a local implementation in_compat.py.j2rather than imported fromgoogle-api-core. The implementation ingoogle-api-core==2.33.0differs slightly from what the generator expects and will be updated in an upcoming release. Keeping it local avoids dependency mismatches and preserves 100% test coverage.TODO: update
setup_request_idto have try except block once its updated in the upcoming release